package com.sf.dlb.web.controller;


import com.sf.dlb.bean.UserReportBean;
import com.sf.dlb.constant.ResponseConstant;
import com.sf.dlb.service.UserReportServiceBase;
import com.sf.dlb.utils.GsonUtils;
import com.sf.dlb.utils.ResultVOUtil;
import com.sf.dlb.vo.ResultVO;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 举报
 * Created by jing.tan on 2018/12/10.
 */
@RestController
@RequestMapping(value = "/v1/report")
public class UserReportController {
    private static Logger logger = LoggerFactory.getLogger(UserReportController.class);
    @Autowired
    private UserReportServiceBase userReportService;

    /**
     * 举报列表
     * @returns
     */
    @PostMapping(value = "/list")
    @ResponseBody
    public Object reportList(@RequestBody UserReportBean userReportBean) {
        logger.info("reportList start ");
        if(userReportBean.getPage()!=0){
            userReportBean.setPage(userReportBean.getPage()-1);
        }
        if(userReportBean.getSize()==0){
            userReportBean.setSize(20);//默认20条
        }
        ResultVO resultVO= userReportService.reportList(userReportBean);
        logger.info("reportList response json === " + GsonUtils.getInstance().toJson(resultVO));
        return resultVO;
    }
    /**
     * 举报处理
     * @returns
     */
    @PostMapping(value = "/hanlder")
    @ResponseBody
    public Object reportHandler(@RequestBody UserReportBean userReportBean) {
        logger.info("reportHandler start ");
        if(StringUtils.isBlank(userReportBean.getId())){
            return ResultVOUtil.error(ResponseConstant.ERROR,"举报Id不能为空");
        }
        if(StringUtils.isBlank(userReportBean.getProcessWay())){
            return ResultVOUtil.error(ResponseConstant.ERROR,"处理方式不能为空");
        }
        ResultVO resultVO=userReportService.reportHandler(userReportBean.getId(),userReportBean.getProcessWay(),userReportBean.getProcessDesc());
        logger.info("reportHandler response json === " + GsonUtils.getInstance().toJson(resultVO));
        return resultVO;
    }

}
